package newcoder_exp.justPractise;

import org.junit.Test;

public class Pra1 {
    //subary
    public int longestArray(int[] nums1, int[] nums2) {

        int m = nums1.length, n = nums2.length;
        int[][] f = new int[m + 1][n + 1];
        f[0][0] = 0;
        f[0][1] = 0;
        f[1][0] = 0;
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++) {
                f[i][j] = f[i - 1][j - 1];
                if (nums1[i - 1] == nums2[j - 1]) {
                    f[i][j]  += 1;
                }
                f[i][j] = Math.max(f[i][j], Math.max(f[i - 1][j], f[i][j - 1]));
            }
        }
        return f[m][n];
    }

    @Test
    public void test() {
        int[] nums = {1, 3, 4, 5, 7, 8};
        int[] nums2 = {3, 5, 4, 5, 8, 9};
        int res = longestArray(nums, nums2);
        StringBuilder sb = new StringBuilder();
        sb.substring(1);
        System.out.println(res);
    }
}
